<template>
    <div class="mmv-tab">
        <ul class="mmv-tab__list">
            <template v-for="(tab,index) in tabs">
                <li :class="{'mmv-tab__item--active':actived===index}" :key="tab.category" @click="onClick(tab,index)" class="mmv-tab__item">
                    <span :class="{'header__notifycount--show': tab.count>0}" :count-num="tab.count" class="mmv-tab__label">{{tab.name}}</span>
                </li>
            </template>
        </ul>
    </div>
</template>

<script>
export default {
    props: {
        tabs: {
            type: Array,
            required: true,
        },
    },
    data() {
        return {
            actived: 0,
        };
    },
    methods: {
        onClick(tab, index) {
            this.actived = index;
            this.$emit("change", tab, index);
        },
    },
};
</script>

<style lang="less">
.mmv-tab {
    z-index: 5;
    &__list {
        display: flex;
    }
    &__item {
        vertical-align: top;
        text-align: center;
        cursor: pointer;
        font-size: 16px;
        height: 50px;
        line-height: 50px;
        position: relative;
        & + & {
            margin-left: 40px;
        }
        a,
        span {
            color: #333;
            display: block;
        }
        &--active {
            font-weight: 600;
            a,
            span {
                color: #4cc3ff;
            }
            &::before {
                content: " ";
                position: absolute;
                width: 100%;
                bottom: 0;
                left: 0;
                border-bottom: 3px solid #4cc3ff;
            }
        }
    }
    &__label {
        display: inline-block;
        position: relative;
        &--show {
            &-count {
                &::after {
                    content: attr(count-num);
                    font-size: 9px;
                    display: inline-block;
                    height: 12px;
                    line-height: 12px;
                    border-radius: 7px;
                    padding: 0 4px;
                    background-color: #ff667f;
                    position: absolute;
                    left: 100%;
                    top: 3px;
                    border: 1px solid #fff;
                    color: #fff;
                    box-sizing: content-box;
                    transform: translateX(-4px);
                }
            }
        }
    }
}
</style>